package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.lihaoming.BaseRespVo1;
import com.cskaoyan.bean.lihaoming.BaseRespVo2;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.bean.param.User;
import com.cskaoyan.service.UserService;
import com.cskaoyan.util.lihaoming.MyUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lihaoming
 * @Description
 * @Create 2022-06-25 20:38
 * @Version
 */
@RequestMapping("admin")
@RestController
public class UserController {
    @Autowired
    UserService userService;
    // 将Handler方法和权限建立耦合关系，访问这个Handler方法需要注解中的权限

    @RequestMapping("user/list")
    @RequiresPermissions(value = {"admin:user:list","*"},logical = Logical.OR)
    public BaseRespVo2 list(String username,String mobile, BasePageInfo info) {
        CommonData<User> data =  userService.query(username,mobile,info);
        return BaseRespVo2.ok(data);
    }

    @RequestMapping("user/detail")
    @RequiresPermissions(value = {"admin:user:detail","*"},logical = Logical.OR)
    public BaseRespVo2 detail(Integer id){
        User data = userService.queryById(id);
            return BaseRespVo2.ok(data);
        }

    @RequestMapping("user/update")
    @RequiresPermissions(value = {"admin:user:update","*"},logical = Logical.OR)
    public BaseRespVo1 updateUser(@RequestBody User user){
        userService.updateByUserName(user);
        return BaseRespVo1.ok(1);
    }
    @RequestMapping("address/list")
    @RequiresPermissions(value = {"admin:address:list","*"},logical = Logical.OR)
    public BaseRespVo1 AddressList(Integer  userId,String name,BasePageInfo info){
        CommonData<MarketAddress> data= userService.addressList(userId,name,info);
        return BaseRespVo1.ok(data);
    }
    @RequestMapping("collect/list")
    @RequiresPermissions(value = {"admin:collect:list","*"},logical = Logical.OR)
    public BaseRespVo1 CollectList(Integer userId,Integer valueId,BasePageInfo info){
        CommonData<MarketCollect> data=userService.collectList(userId,valueId,info);
        return BaseRespVo1.ok(data);
    }
    @RequestMapping("footprint/list")
    @RequiresPermissions(value = {"admin:footprint:list","*"},logical = Logical.OR)
    public BaseRespVo1 FootPrint(Integer userId,Integer goodsId,BasePageInfo info){
        CommonData<MarketFootprint> data=userService.footPrintList(userId,goodsId,info);

        return BaseRespVo1.ok(data);
    }
    @RequestMapping("history/list")
    @RequiresPermissions(value = {"admin:history:list","*"},logical = Logical.OR)
    public BaseRespVo1 HistoryList(Integer userId,String keyword,BasePageInfo info){
        CommonData<MarketSearchHistory> data=userService.historyList(userId,keyword,info);
        return BaseRespVo1.ok(data);
    }
    @RequestMapping("feedback/list")
    @RequiresPermissions(value = {"admin:feedback:list","*"},logical = Logical.OR)
    public BaseRespVo1 FeedBackList(String username,Integer id,BasePageInfo info){
        CommonData<MarketFeedback> data=userService.feedbackList(username,id,info);
        return BaseRespVo1.ok(data);
    }


}
